<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title></title>
		<link href="<%=request.getContextPath()%>/static/mobile/ywym/css/swiper.min.css" type="text/css" rel="stylesheet" />
		<link href="<%=request.getContextPath()%>/static/mobile/ywym/css/index.css" type="text/css" rel="stylesheet" />
	</head>

	<body>
		<div class="yardMain">
			<div class="swiper-container">
				<div class="swiper-wrapper">
				

				</div>
				<!-- Add Pagination -->
				<!--   <div class="swiper-pagination"></div> -->
				<div class="swiper-button-next"></div>
				<div class="swiper-button-prev"></div>
			</div>
			<!--
          	作者：offline
          	时间：2018-03-19
          	描述：底部内容
          -->
			<div class="footercode"></div>
			<div class="footer">
		        <marquee behavior="scroll"  class="footerfont">友惠家招商加盟热线：43243235242 　　扫描右侧二维码了解详情</marquee>
		     </div>
		</div>
		<!--
        	作者：lanlimei
        	时间：2018-03-20
        	描述：京东蒙版
        -->
		<div class="jdmask">
			
		</div>
		<!--
        	作者：lanliemi
        	时间：2018-03-20
        	描述：友惠蒙版
        -->
		<div class="yhmask">
			<div class="yhmaskcon"></div>
			<div class="yhclosebut"><img src="<%=request.getContextPath()%>/static/mobile/ywym/images/closebut.png"></div>
		</div>
		<div class="videos" style="width:90%;margin:0 auto;"></div>
		<script src="<%=request.getContextPath()%>/static/mobile/ywym/js/jquery-1.9.1.min.js"></script>
		<script src="<%=request.getContextPath()%>/static/mobile/ywym/js/swiper.min.js"></script>
		<script type="text/javascript" src="<%=request.getContextPath()%>/static/js/sockjs-0.3.min.js"></script>
		<script type="text/javascript">
			

			var href = window.location.href;
			var userid = href.split('?')[1].split('=')[1];
			var wsurl = ${wsurl};
			var websocket;
			if('WebSocket' in window) {
				websocket = new WebSocket(wsurl + "/webSocketServer");
			} else if('MozWebSocket' in window) {
				websocket = new MozWebSocket(wsurl + "/webSocketServer");
			} else {
				websocket = new SockJS(wsurl + "/sockjs/webSocketServer");
			}
			websocket.onopen = function(evnt) {};
			websocket.onmessage = function(evnt) {
				var html = "";
				var listData = eval("(" + evnt.data + ")");
				console.log(listData);
				var compyjson = listData.advert;
				//gongsiguanggao
				$(".footerfont").html(compyjson.word);
				$(".footercode").html('<img src="'+compyjson.qcode+'">')
				var changUrl,nowtimes,i = 0;
				var currentId = "";
				setInterval(function() {

					var now = listData.currentTime;
					// var nowTimes= Date.parse(now)+i*1000;
					i++;
					var nowTimes = Date.parse(new Date());
					var myDate = new Date(); //获取系统当前时间
					var month = myDate.getMonth() + 1
					var timeYear = myDate.getFullYear() + '-' + month + '-' + myDate.getDate();
					console.log(currentId);
					var timeJson = listData.list;
					//var timeYear =  now.split(' ')[0];
					for(var j = 0; j < timeJson.length; j++) {

						var startime = Date.parse(timeYear + ' ' + timeJson[j].startTime) + 1000;
						var endtime = Date.parse(timeYear + ' ' + timeJson[j].endTime) + 1000;
						if((startime <= nowTimes) && (nowTimes <= endtime)) {

							if(timeJson[j].id != currentId) {

								if(timeJson[j].type == "video") {
									result = true;
									$(".swiper-container").hide();
									$(".videos").show();
									$(".videos").html('<video  loop="loop" controls="controls" autoplay="autoplay" style="width:100%;">' +
										'<source src="' + timeJson[j].videoUrl + '" type="video/ogg" />' +
										'<source src="' + timeJson[j].videoUrl + '" type="video/mp4" />' +
										'</video>');
									// arrtId = 1;
									currentId = timeJson[j].id;
								} else {
									result = true;
									$(".swiper-container").show();
									$(".videos").hide();
									goods();
									//arrtId = 1;
									currentId = timeJson[j].id;

								}

							}
						}

					}

				}, 1000)
			}
			websocket.onerror = function(evnt) {};
			websocket.onclose = function(evnt) {}
			function goods(){
				$.ajax({
					url: "http://develop.jhjvip.cn:8080/mall/mobile/ywym/list",
					type: 'get',
					dataType: 'json',
					data: {
						userid: userid,

					},
					success: function(response) {
						if(response.code == "10000"){
							var json = response.data;
							console.log(json);
							var html='';
							for(var i=0;i<json.length;i++){
								console.log(json[i].spuPlatform);
								if(json[i].spuPlatform == "jd"){
									html += '<div class="swiper-slide" data_id="'+json[i].id+'" data_name="'+json[i].spuPlatform+'">'
											+'<div class="depriceimg">'+'直降'+json[i].conPrice+'元'+'</div>'
											+'<div class="goodimg"><img src="'+json[i].mainImageUrl+'"></div>'
											+'<div class="goodname"><img src="<%=request.getContextPath()%>/static/mobile/ywym/images/jdLogo.png" class="picSymbol">'+json[i].goodsName+'</div>'
											+'<div class="costarea">'
												+'<span class="leftcost">特惠价:<span class="activePrcie"><i class="actpriceSymbol">￥</i>'+json[i].orginPrice+'</span></span>'
												+'<span class="righcost">京东价:￥'+json[i].price+'</span>'
											+'</div>'
											+'<div class="detaiBut">点击查看商品详情</div>'
											+'</div>'
								}else{
									html += '<div class="swiper-slide" data_id="'+json[i].id+'" data_name="'+json[i].spuPlatform+'">'
											+'<div class="depriceimg">'+'直降'+json[i].conPrice+'元'+'</div>'
											+'<div class="goodimg"><img src="'+json[i].mainImageUrl+'"></div>'
											+'<div class="goodname">'+json[i].goodsName+'</div>'
											+'<div class="costarea">'
												+'<span class="leftcost">特惠价:<span class="activePrcie"><i class="actpriceSymbol">￥</i>'+json[i].orginPrice+'</span></span>'
												+'<span class="righcost">友惠价:￥'+json[i].price+'</span>'
											+'</div>'
											+'<div class="detaiBut">点击查看商品详情</div>'
											+'</div>'
								}
								
								
							}
							$(".swiper-wrapper").html(html);
							swiperCon();
							
						}
					}
				})
			}
			//轮播事件
			function  swiperCon(){
				var swiper = new Swiper('.swiper-container', {
					autoplay:true,
	
					slidesPerView: 4,
					slidesPerColumn: 2,
					spaceBetween: 30,
					pagination: {
						el: '.swiper-pagination',
						clickable: true,
					},
					navigation: {
						nextEl: '.swiper-button-next',
						prevEl: '.swiper-button-prev',
	
					},
				});
				
				
				$(".yhclosebut").on("click", function() {
					$(".yhmask").hide()
				})
				//点击事件
				$(".swiper-slide").on('click', function() {
					
					var proname = $(this).attr('data_name');
					var id = $(this).attr('data_id');
					
					if(proname == "jd"){
						//alert(id);
						$(".yhmask").hide();
						$(".jdmask").show();
						jdDeail(id);
						
					}else{
						$(".jdmask").hide();
						$(".yhmask").show();
						yhDetail(id);
					}
				})
			}
			//京东详情
			function jdDeail(obj){
				//alert(obj)
				$.ajax({
						url: "http://develop.jhjvip.cn:8080/mall/mobile/ywym/detail",
						type: 'get',
						dataType: 'json',
						data: {
							userid: userid,
							goodsid: obj
						},
						success: function(data) {
							//console.log(data);
							var jdhtml = ''
							if(data.code == "10000"){
								var json = data.data
							    jdhtml = '<div class="jdleftmain">'
										   +'<div class="cutimg">'
											  +'<span class="cutitle">直降</span>'
										      +'<span class="cutprice">'+json.couponMoney+'元</span>'
											+'</div>'
											+'<div class="jdimg"><img src="'+json.mainImageUrl+'"></div>'
											+'<div class="jdgoodname"><img src="<%=request.getContextPath()%>/static/mobile/ywym/images/JD.png" class="JDSymbol">'+json.name+'</div>'
											+'<div class="jdcost">'
												+'<span class="activename">特惠价：</span>'
												+'<span class="activePrice"><i class="jdSymbol">￥</i>'+json.conPrice+'</span>'
											+'</div>'
											+'<div class="totalArea">'
												+'<span class="jdOrginprice">京东价：<i class="Orginprice">￥'+json.price+'</i></span>'
												+'<span class="totalsum">销量：'+json.totalSales+'</span>'
											+'</div>'
										+'</div>'
									+'<div class="jdrightmain">'
										+'<div class="closebut"><img src="<%=request.getContextPath()%>/static/mobile/ywym/images/closebut.png"></div>'
										+'<div class="jdRoeeprice"><i class="jdResymbol">￥</i>'+json.couponMoney+'</div>'
										+'<div class="jdcodeimg"><img src="'+json.qcodeUrl+'"></div>'
									+'</div>'
								$(".jdmask").html(jdhtml);
								//关闭按钮
								$(".closebut").on("click", function() {
									$(".jdmask").hide()
								})
							}else{
								alert(data.msg);
							}
						}
					})
			}
			//友惠详情
			function yhDetail(obj){
				//alert(obj)
				$.ajax({
						url: "http://develop.jhjvip.cn:8080/mall/mobile/ywym/detail",
						type: 'get',
						dataType: 'json',
						data: {
							userid: userid,
							goodsid: obj
						},
						success: function(data) {
							console.log(data);
							var yhhtml = '';
							if(data.code == "10000"){
							      var yhjson = data.data;
							      var img = yhjson.detailImageUrls.split(',');
							      
							      
							      yhhtml = '<div class="yhleftmain">'
										  +'<div class="cutimg">'
											+'<span class="cutitle">直降</span>'
											+'<span class="cutprice">'+yhjson.couponMoney+'元</span>'
										  +'</div>'
										  +'<div class="yhimg"><img src="'+yhjson.mainImageUrl+'"></div>'
										  +'<div class="jdgoodname"><img src="<%=request.getContextPath()%>/static/mobile/ywym/images/yh.png" class="jdSymbol">'+yhjson.name+'</div>'
										  +'<div class="yhstage">'
										  +'<div class="yhcost">'
										 	 +'<span class="yhOrignprice">特惠价：<span class="orignpricesum"><i class="orignSymbol">￥</i>'+yhjson.conPrice+'</span></span>'
											 +'<span class="samefontsty">友惠价:￥'+yhjson.price+'</span>'
											 +'<span class="samefontsty">销量:'+yhjson.totalSales+'</span>'
										  +'</div>'
										  +'<div class="yhcodecon">'
										  	+'<div class="yhcodeimg"><img src="'+yhjson.qcodeUrl+'"></div>'
										  +'</div>'
										  +'</div>'
										  +'<div class="checkbut">扫码查看</div>'
										  +'</div>'
										  +'<div class="yhrightmain"></div>'
			
									$(".yhmaskcon").html(yhhtml);
									for(var i=0; i<img.length;i++){
							      		
							      		$(".yhrightmain").append('<img src="'+img[i]+'">')
							      	}
							}else{
								alert(data.msg);
							}
						}
					})
			}
		</script>

	</body>

</html>